//
//  HMTabBarController.swift
//  sina
//
//  Created by Kent on 16/9/22.
//  Copyright © 2016年 Ming. All rights reserved.
//

import UIKit

class HMTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let hmTabBar = HMTabBar()
        
        hmTabBar.composeClosure = { [weak self] in
            
            print("compose Clicked",self)
            
        }
        
        self.setValue(hmTabBar, forKey: "tabBar")
        
        addControllers()
        
    }
    
    private func addControllers() {
        
        addChildViewController(vc: HMHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(vc: HMMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(vc: HMDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(vc: HMProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    
    private func addChildViewController(vc: UIViewController,title: String,imageName: String) {
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 11)], for: .normal)
        
        vc.tabBarItem.badgeColor = UIColor.purple
        
        vc.tabBarItem.badgeValue = nil
        
        let nav = HMNavController(rootViewController: vc)
        
        addChildViewController(nav)
    }
    
    
    

}





































